

using System;
using System.Collections.Generic;
using System.Text;
using DataAccessLayer;
using EntityLayer;
using DataLayer;
using System.Data;
using InfraStructureLayer;

namespace BusinessLayer
{
    public class busUsers : BusinessBase
    {
        public busUsers()
            : base()
        {
        }
        #region  Code Factory Generated Methods
        public void DeleteUsersByUserId(entUsers parEntUsers)
        {
            DbConnector insDbConnector = new DbConnector();
            try
            {
                datUsers insDatUsers = new datUsers();
                insDatUsers.DeleteUsersByUserId(parEntUsers, insDbConnector);
            }
            catch (SFException ex)
            {
                this.ErrorMessage = ex.Message;
            }
        }

        public DataTable SelectUsers()
        {
            try
            {
                datUsers insDatUsers = new datUsers();
                DbConnector insDbConnector = new DbConnector();
                return insDatUsers.SelectUsers(insDbConnector);
            }
            catch (SFException ex)
            {
                this.ErrorMessage = ex.Message;
            }
            return null;
        }
        public void SelectUsersByUserId(entUsers parEntUsers)
        {
            try
            {
                datUsers insDatUsers = new datUsers();
                DbConnector insDbConnector = new DbConnector();
                insDatUsers.SelectUsersByUserId(parEntUsers, insDbConnector);
            }
            catch (SFException ex)
            {
                this.ErrorMessage = ex.Message;
            }
        }

        #endregion
        public void InsertUsers(entUsers parEntUsers)
        {
            datUsers insDatUsers = null;
            DbConnector insDbConnector = new DbConnector();
            try
            {
                insDatUsers = new datUsers();
                if (insDatUsers.CheckUsersExists(parEntUsers, insDbConnector))
                {
                    throw new SFBusinessException(GetErrorMessageMultilanguageString(11, new object[] { }));
                }
                parEntUsers.UserPassword = InfraStructureLayer.MD5Crypto.Tomd5(parEntUsers.UserPassword);
                insDatUsers.InsertUsers(parEntUsers, insDbConnector);
            }
            catch (SFException ex)
            {
                this.ErrorMessage = ex.Message;
            }
        }
        public void UpdateUsersByUserId(entUsers parEntUsers)
        {

            datUsers insDatUsers = null;
            DbConnector insDbConnector = new DbConnector();
            try
            {
                insDatUsers = new datUsers();
                if (insDatUsers.CheckUsersExists(parEntUsers, insDbConnector))
                {
                    throw new SFBusinessException(GetErrorMessageMultilanguageString(11, new object[] { }));
                }
                parEntUsers.UserPassword = InfraStructureLayer.MD5Crypto.Tomd5(parEntUsers.UserPassword);
                insDatUsers.UpdateUsersByUserId(parEntUsers, insDbConnector);
            }
            catch (SFException ex)
            {
                this.ErrorMessage = ex.Message;
            }
        }
  
        public void SelectUsersByUserNameAndUserPassword(entUsers parEntUsers)
        {
            try
            {
                datUsers insDatUsers = new datUsers();
                DbConnector insDbConnector = new DbConnector();
                parEntUsers.UserPassword = InfraStructureLayer.MD5Crypto.Tomd5(parEntUsers.UserPassword);
                insDatUsers.SelectUsersByUserNameAndUserPassword(parEntUsers, insDbConnector);
            }
            catch (SFException ex)
            {
                this.ErrorMessage = ex.Message;
            }
        }
        public void ChangeUserPassword(entUsers parEntUsers, string newPassword)
        {
            try
            {
                datUsers insDatUsers = new datUsers();
                DbConnector insDbConnector = new DbConnector();

                entUsers insEntUsers = new entUsers();
                insEntUsers.UserId = parEntUsers.UserId;

                insDatUsers.SelectUsersByUserId(insEntUsers, insDbConnector);

                if (insEntUsers.UserPassword != InfraStructureLayer.MD5Crypto.Tomd5(parEntUsers.UserPassword))
                {
                    throw new SFBusinessException(GetErrorMessageMultilanguageString(27, new object[] { }));
                }
                insEntUsers.UserPassword = InfraStructureLayer.MD5Crypto.Tomd5(newPassword);
                insDatUsers.UpdateUsersByUserId(insEntUsers, insDbConnector);
            }
            catch (SFException ex)
            {
                this.ErrorMessage = ex.Message;
            }
        }
    }
}